package com.xy.job.executor.log.factory

import com.xy.job.executor.log.logger.Log4jLogger
import com.xy.job.executor.log.logger.Logger
import org.apache.log4j.Hierarchy
import org.apache.log4j.Level
import org.apache.log4j.spi.LoggerRepository
import org.apache.log4j.spi.RootLogger
import org.apache.log4j.xml.DOMConfigurator
import java.net.URL

internal class Log4jLoggerFactory : ILoggerFactory {

    private var repository: LoggerRepository

    init {
        Class.forName("org.apache.log4j.Level")
        repository = Hierarchy(RootLogger(Level.DEBUG))
        val url: URL = Log4j2LoggerFactory::class.java.getResource("/log4j-xy-job.xml")!!
        DOMConfigurator().doConfigure(url, repository)
    }

    override fun getLogger(name: String?): Logger {
        return Log4jLogger(repository.getLogger(name))
    }

}